<template>
  <div class="tab-control">
    <div
      v-for="(item, index) in titles"
      :key="item"
      class="item"
      :class="{ active: index === currentIndex}"
      @click="itemClick(index)">
      <span>{{ item }}</span>
    </div>
  </div>
</template>

<script>
export default {
  name: "TabControl",
  components: {},
  props: {
    titles: {
      type: Array,
      default() {
        return [];
      },
    },
  },
  data() {
    return {
      currentIndex: 0,
    };
  },
  watch: {},
  computed: {},
  methods: {
    itemClick(data) {
      this.currentIndex = data;
      this.$emit("tabbarClick",this.currentIndex);
    },
  },
  created() {},
  mounted() {},
};
</script>
<style lang="less" scoped>
.tab-control {
  display: flex;
  font-size: 16px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  background-color: #fff;
  .item {
    flex: 1;
  }
  .active {
    color: var(--color-high-text);
    span {
      padding: 3px;
      border-bottom: 4px solid var(--color-high-text);
    }
  }
}
</style>